package com.aat.dxfy.http;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;

public class Test01 {

	public static void main(String[] args) {
		MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
		HttpClient client = new HttpClient(connectionManager);
		
		String url = "http://ip.taobao.com/service/getIpInfo.php?ip=124.126.17.179";
		
		GetMethod get = new GetMethod(url);
		try {
			get.addRequestHeader("User-Agent",
					"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0");
			get.addRequestHeader("Accept-Encoding", "gzip, deflate");
			
			client.executeMethod(get);
			get.getResponseBodyAsStream();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			get.releaseConnection();
		}
	}

	public static void test(){
		MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
		HttpClient client = new HttpClient(connectionManager);
		GetMethod get = new GetMethod("http://httpcomponents.apache.org/");
		try {
			client.executeMethod(get);
			System.out.println(get.getResponseBodyAsStream());
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			get.releaseConnection();
		}
	}
}
